<template>
  <div class="tips-info">
    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">视图设置</el-divider>
      </div>
      <el-form-item label="区域高度" v-if="!!(optionsInfo.contentHeight)">
        <el-input-number :min="0" size="small" v-model="optionModel.tipsConfig.contentHeight"/>
      </el-form-item>
      <el-form-item label="背景颜色">
        <el-color-picker
            size="small"
            :predefine="predefineColors"
            show-alpha v-model="optionsInfo.backgroundColor"
        />
      </el-form-item>
      <el-form-item label="视图模式">
        <el-select
            v-model="optionsInfo['viewMode']"
            placeholder="请选择"
            @change="handleChangeView"
        >
          <el-option
              v-for="item in viewModelOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </el-form-item>
    </div>

    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">温馨提示设置</el-divider>
      </div>
      <el-form-item label="温馨提示" class="column-area">
        <el-input :min="0" type="textarea" size="small" :autosize="{ minRows: 2, maxRows: 4 }" class="hide-spin-button"
                  v-model="optionsInfo.contentInfo"/>
      </el-form-item>
<!--      <el-form-item label="是否滚动">-->
<!--        <el-switch v-model="optionsInfo.scrollable"/>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="滚动速度(设备比例*19.2*速率/s)" v-if="!!(optionModel.tipsConfig.scrollable)"-->
<!--                    class="column-area">-->
<!--        <el-input-number :precision="1" :min="1" :max="20" size="small" v-model="optionModel.tipsConfig.speed"/>-->
<!--      </el-form-item>-->
    </div>

    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">图标设置</el-divider>
      </div>
      <el-form-item label="显示图标">
        <el-switch v-model="optionsInfo.iconVisit"/>
      </el-form-item>
      <el-form-item label="图标大小">
        <el-input-number :min="0" size="small" v-model="optionsInfo.headerFontSize"/>
      </el-form-item>
      <el-form-item label="图标颜色">
        <el-color-picker v-model="optionsInfo.headerColor" size="small" show-alpha
                         :predefine="predefineColors"/>
      </el-form-item>
    </div>

    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">内容设置</el-divider>
      </div>
      <el-form-item label="字体大小">
        <el-input-number :min="0" size="small" v-model="optionsInfo.listFontSize"/>
      </el-form-item>
      <el-form-item label="粗细设置">
        <el-select v-model="optionsInfo.listFontWeight" placeholder="请选择">
          <el-option v-for="item in fontWeightOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="字体颜色">
        <el-color-picker v-model="optionsInfo.listFontColor" size="small" show-alpha
                         :predefine="predefineColors"/>
      </el-form-item>
      <el-form-item label="文本位置" v-if="optionsInfo.contentLocation">
        <el-select v-model="optionsInfo.contentLocation" placeholder="请选择">
          <el-option
            v-for="item in contentLocationList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="顶部外边距">
        <el-input-number :min="0" size="small" v-model="optionsInfo.marginTop"/>
      </el-form-item>
      <el-form-item label="图标类型">
        <el-select v-model="optionsInfo['iconType']" placeholder="请选择">
          <el-option v-for="item in iconOptions" :key="item.value" :label="item.label" :value="item.value">
            <Icon :name="item.value"/>
          </el-option>
        </el-select>
      </el-form-item>
    </div>
  </div>
</template>

<script>
import {Icon} from 'vant';
import constantDic from "@/utils/vue-i18n/lang/zh-CN";
import * as types from "@c/public/form-designer/devType/datas-types";

export default {
  name: "tipsConfig-editor",

  componentName: "tipsConfig-editor",

  mixins: [],

  components: {
    Icon
  },

  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object,
  },

  inject: ['serverFieldList', 'getDesignerConfig'],

  data() {
    return {
      optionsInfo: Object(),
      fontWeightOptions: types['fontWeightOptions'],
      constantDic: constantDic,
      predefineColors: types['predefineColors'],
      iconOptions: [
        {
          value: 'volume',
          label: '图标1'
        },
        {
          value: 'bell',
          label: '图标2'
        }
      ],
      viewModelOptions: [
        {
          value: 1,
          label: "视图一",
        },
        {
          value: 2,
          label: "视图二",
        }
      ],
      contentLocationList: [
        {
          value: "left",
          label: "左",
        },
        {
          value: "center",
          label: "中",
        }
      ]
    }
  },

  methods:{
    // 视图模式
    handleChangeView(val) {
      switch (val) {
        case 1:
          Reflect.set(this.optionsInfo,'contentHeight',100)
          Reflect.set(this.optionsInfo,'headerFontSize',66)
          Reflect.set(this.optionsInfo,'listFontSize',40)
          break
        case 2:
          Reflect.set(this.optionsInfo,'contentHeight',60)
          Reflect.set(this.optionsInfo,'headerFontSize',56)
          Reflect.set(this.optionsInfo,'listFontSize',32)
          break
      }
    },
  },

  watch: {
    // 组件的所有信息
    optionModel: {
      handler: function (val) {
        this.optionsInfo = val[val.config];
      },
      deep: true,
      immediate: true
    }
  }

}
</script>


<style lang="scss" scoped>
.column-area {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
    margin-bottom: 10px;
  }

  :deep(.el-form-item__content) {
    width: 100%;
    margin-left: 0 !important;

    .el-radio-group {
      width: 100%;
      display: flex;
      flex-direction: column;

      .el-radio {
        margin-bottom: 10px;
      }
    }
  }

}
</style>
